package co.fitstart.coach.web.controller.courseware;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo2do.core.support.Result;
import com.demo2do.core.utils.JsonUtils;

import co.fitstart.coach.entity.courseware.MovementSearch;
import co.fitstart.coach.service.CoursewareService;
import co.fitstart.entity.courseware.movement.Movement;

/**
 * 
 * @author dan
 *
 */
@Controller
@RequestMapping("/movements")
public class MovementController {
    
    private static final Logger logger = LoggerFactory.getLogger(MovementController.class);
    
    @Autowired
    private CoursewareService coursewareService;
    
    /**
     * 
     * @param movementSearch
     * @return
     */
    @RequestMapping(value = "", method = RequestMethod.GET, params = "filter")
    public @ResponseBody String onSearch(MovementSearch movementSearch) {
        
        Result result = new Result();
        
        try {
            
            List<Movement> movements = coursewareService.searchMovement(movementSearch);
            
            result.success().data("movements", movements).message("查询动作成功");
            
        } catch (Exception e) {
            
            logger.error("onSearch - ", e);
            result.fail().message("查询动作失败");
            
        }
        
        return JsonUtils.toJsonString(result);
    }
}
